/*
    This file is part of SQLiteGTK, written by Aly Hirani

    SQLiteGTK is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SQLiteGTK is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with SQLiteGTK.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "include.h"
#include "main_window_notebook.h"
#include "util.h"

void
main_window_menu_edit_execute_activate_cb(GtkMenuItem *menu_item, gpointer user_data)
{
}

void
main_window_menu_edit_activate_cb(GtkMenuItem *menu_item, gpointer user_data)
{
	GtkBuilder *builder;
	GtkAction *menu_edit_undo, *menu_edit_redo, *menu_edit_cut, *menu_edit_copy, *menu_edit_paste, *menu_edit_delete, *menu_edit_execute;
	
	D_ASSERT(menu_item != NULL);
	D_ASSERT(user_data != NULL);
	
	builder = GTK_BUILDER(user_data);
	D_ASSERT(builder != NULL);
	
	menu_edit_undo = GTK_ACTION(gtk_builder_get_object(builder, "menu_edit_undo"));
	D_ASSERT(menu_edit_undo != NULL);
	
	menu_edit_redo = GTK_ACTION(gtk_builder_get_object(builder, "menu_edit_redo"));
	D_ASSERT(menu_edit_redo != NULL);
	
	menu_edit_cut = GTK_ACTION(gtk_builder_get_object(builder, "menu_edit_cut"));
	D_ASSERT(menu_edit_cut != NULL);
	
	menu_edit_copy = GTK_ACTION(gtk_builder_get_object(builder, "menu_edit_copy"));
	D_ASSERT(menu_edit_copy != NULL);
	
	menu_edit_paste = GTK_ACTION(gtk_builder_get_object(builder, "menu_edit_paste"));
	D_ASSERT(menu_edit_paste != NULL);
	
	menu_edit_delete = GTK_ACTION(gtk_builder_get_object(builder, "menu_edit_delete"));
	D_ASSERT(menu_edit_delete != NULL);
	
	menu_edit_execute = GTK_ACTION(gtk_builder_get_object(builder, "menu_edit_execute"));
	D_ASSERT(menu_edit_delete != NULL);

/* TODO: THIS SHOULD NOT BE HERE?! WTF */
/*
	if(main_window_notebook_is_active_page_type(main_window_notebook_get_notebook_from_builder(builder), MWNPT_EDITOR))
	{
		GtkSourceView *source_view;
		GtkSourceBuffer *source_buffer;
		GtkBuilder *page_builder;
		gboolean has_selection;
	
		page_builder = main_window_notebook_get_active_page_builder_from_builder(builder);
		g_assert(page_builder);
		
		source_view = GTK_SOURCE_VIEW(gtk_builder_get_object(page_builder, "source_view"));
		D_ASSERT(source_view != NULL);
		
		source_buffer = GTK_SOURCE_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(source_view)));
		D_ASSERT(source_buffer != NULL);
		
		gtk_action_set_sensitive(menu_edit_undo, gtk_source_buffer_can_undo(source_buffer));
		gtk_action_set_sensitive(menu_edit_redo, gtk_source_buffer_can_redo(source_buffer));
		
		has_selection = gtk_text_buffer_get_has_selection(GTK_TEXT_BUFFER(source_buffer));
		
		gtk_action_set_sensitive(menu_edit_cut, has_selection);
		gtk_action_set_sensitive(menu_edit_copy, has_selection);
		gtk_action_set_sensitive(menu_edit_paste, TRUE);
		gtk_action_set_sensitive(menu_edit_delete, has_selection);
		gtk_action_set_sensitive(menu_edit_execute, TRUE);
	}
	else
	{
		gtk_action_set_sensitive(menu_edit_undo, FALSE);
		gtk_action_set_sensitive(menu_edit_redo, FALSE);
		gtk_action_set_sensitive(menu_edit_cut, FALSE);
		gtk_action_set_sensitive(menu_edit_copy, FALSE);
		gtk_action_set_sensitive(menu_edit_paste, FALSE);
		gtk_action_set_sensitive(menu_edit_delete, FALSE);
		gtk_action_set_sensitive(menu_edit_execute, FALSE);
	}
	*/
}

void
main_window_menu_edit_undo_activate_cb(GObject* object, gpointer user_data)
{
	/*
	GtkSourceView *source_view;
	GtkSourceBuffer *source_buffer;
	GtkBuilder *page_builder;
	
	g_assert(object != NULL);
	g_assert(user_data != NULL);
	g_assert(main_window_notebook_is_active_page_type(user_data, MWNPT_EDITOR));
	
	page_builder = main_window_notebook_get_active_page_builder_from_user_pointer(user_data);
	g_assert(page_builder);
	
	source_view = GTK_SOURCE_VIEW(gtk_builder_get_object(page_builder, "source_view"));
	g_assert(source_view != NULL);
	
	source_buffer = GTK_SOURCE_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(source_view)));
	g_assert(source_buffer != NULL);
	
	gtk_source_buffer_undo(page_type_editor.source_buffer);
	*/
}

void
main_window_menu_edit_redo_activate_cb(GObject* object, gpointer user_data)
{
	/*
	g_assert(object != NULL);
	g_assert(user_data != NULL);
	
	MainWindowControls *controls = main_window_notebook_get_active_controls(user_data, MWCT_EDITOR_SOURCE_BUFFER);
	g_assert(controls != NULL);
	g_assert(controls->notebook_page_type == MWNPT_EDITOR);
	g_assert(controls->notebook_page_controls.page_type_editor.source_buffer != NULL);
	
	gtk_source_buffer_redo(controls->notebook_page_controls.page_type_editor.source_buffer);
	
	g_free(controls);
	*/
}

void
main_window_menu_edit_cut_activate_cb(GObject* object, gpointer user_data)
{
	/*
	g_assert(object != NULL);
	g_assert(user_data != NULL);
	
	MainWindowControls *controls = main_window_notebook_get_active_controls(user_data, MWCT_EDITOR_SOURCE_BUFFER);
	g_assert(controls != NULL);
	g_assert(controls->notebook_page_type == MWNPT_EDITOR);
	g_assert(controls->notebook_page_controls.page_type_editor.source_buffer != NULL);
	
	gtk_text_buffer_cut_clipboard(GTK_TEXT_BUFFER(controls->notebook_page_controls.page_type_editor.source_buffer), selection_clipboard, TRUE);
	
	g_free(controls);
	*/
}

void
main_window_menu_edit_copy_activate_cb(GObject* object, gpointer user_data)
{
	/*
	g_assert(object != NULL);
	g_assert(user_data != NULL);
	
	MainWindowControls *controls = main_window_notebook_get_active_controls(user_data, MWCT_EDITOR_SOURCE_BUFFER);
	g_assert(controls != NULL);
	g_assert(controls->notebook_page_type == MWNPT_EDITOR);
	g_assert(controls->notebook_page_controls.page_type_editor.source_buffer != NULL);
	
	gtk_text_buffer_copy_clipboard(GTK_TEXT_BUFFER(controls->notebook_page_controls.page_type_editor.source_buffer), selection_clipboard);
	
	g_free(controls);
	*/
}

void
main_window_menu_edit_paste_activate_cb(GObject* object, gpointer user_data)
{
	/*
	g_assert(object != NULL);
	g_assert(user_data != NULL);
	
	MainWindowControls *controls = main_window_notebook_get_active_controls(user_data, MWCT_EDITOR_SOURCE_BUFFER);
	g_assert(controls != NULL);
	g_assert(controls->notebook_page_type == MWNPT_EDITOR);
	g_assert(controls->notebook_page_controls.page_type_editor.source_buffer != NULL);
	
	gtk_text_buffer_paste_clipboard(GTK_TEXT_BUFFER(controls->notebook_page_controls.page_type_editor.source_buffer), selection_clipboard, NULL, TRUE);
	
	g_free(controls);
	*/
}

void
main_window_menu_edit_delete_activate_cb(GObject* object, gpointer user_data)
{
	/*
	g_assert(object != NULL);
	g_assert(user_data != NULL);
	
	MainWindowControls *controls = main_window_notebook_get_active_controls(user_data, MWCT_EDITOR_SOURCE_BUFFER);
	g_assert(controls != NULL);
	g_assert(controls->notebook_page_type == MWNPT_EDITOR);
	g_assert(controls->notebook_page_controls.page_type_editor.source_buffer != NULL);
	
	gtk_text_buffer_delete_selection(GTK_TEXT_BUFFER(controls->notebook_page_controls.page_type_editor.source_buffer), TRUE, TRUE);
	
	g_free(controls);
	*/
}

